<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<% 
	String start_date = request.getParameter("start_date") == null ? "" : request.getParameter("start_date");
	String end_date = request.getParameter("end_date") == null ? "" : request.getParameter("end_date");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String type = request.getParameter("type") == null ? "" : request.getParameter("type");
%>
<html>
	<head>
		<title>项目管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$('#xm_progress_status').combobox({
				 url:'<%=contextPath%>/springMVC/xm/listXMProcessStatuc',
				 valueField:'id',
				 textField:'text',
				 onChange:function(){
						doSearch();
					}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			var xmStatus = new Array("新建","未开工", "在建", "完工", "验收", "送审", "开票" ,"结算", "关闭"); 
			$("#table").datagrid({
				title:"项目管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/statistic/listPageXMBase?end_date=<%=end_date%>&dept_id=<%=dept_id%>&type=<%=type%>&start_date=<%=start_date%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'项目进度',field:'xm_progress_status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						return xmStatus[value];
					}},
					{title:'所属部门',field:'admin_dept',width:100,align:'center'},
					{title:'建设单位编号',field:'construct_code',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'客户',field:'customer',width:120,align:'center'},
					{title:'是否发起无合同申请',field:'contract_type',hidden:true},
					{title:'开工时间',field:'start_time',width:100,align:'center'},
					{title:'完工时间',field:'end_time',width:100,align:'center'},
					{title:'绑定工单数量',field:'xm_gds_num',width:100,align:'center'},
			
					{title:'详情',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						
	                    str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='项目详情' onclick=\"javascript:viewData('"+rowData.id+"','"+rowData.xm_flow_status+"');\"/>";
	                    return str;
					}}
				]],
				view: detailview,
				detailFormatter:function(index,row){
					return '<div style="padding:2px"><table class="ddv"></table></div>';
				},
				onExpandRow: function(index,row){
					var xm_id = row.id;
					var xm_flow_status = row.xm_flow_status;
					var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
					var url="";
					if(xm_flow_status == 0){
						url = "<%=contextPath%>/springMVC/gd/listPageTmpGd?xm_id="+xm_id;
					}else{
						url="<%=contextPath%>/springMVC/gd/listGd?xm_id="+xm_id;
					}
					 ddv.datagrid({
						title:'工单明细',
						url:url,
						loadMsg:'正在加载数据，请稍后......',
						fitColumns:true,
						rownumbers:true,
						columns:[[
							{title:'工单id',field:'id',hidden:true},
							{title:'工单内容id',field:'gd_content_id',hidden:true},
							{title:'工单状态',field:'gd_status',hidden:true},
							{title:'工单进度',field:'gd_status_desc',width:50,align:'center'},
							{title:'工单编号',field:'gd_code',width:100,align:'center'},
							{title:'工单名称',field:'gd_name',width:200,align:'center'},
							{title:'开工日期',field:'gd_start',width:150,align:'center'},
							{title:'完工日期',field:'gd_actual_end',width:150,align:'center'},
							{title:'操作',field:'edit',width:80,align:'center',formatter:function(value,rowData,rowIndex){
								return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看详情' onclick=\"javascript:showGD('"+rowData.id+"','"+rowData.gd_content_id+"');\"/>";
							}}
						]],
						pageSize:10,
						pageList : [10,50,100],  
						pagination:true,
					 	onResize:function(){
					        $('#table').datagrid('fixDetailRowHeight',index);
					    },
					 	onLoadSuccess:function(){
					       setTimeout(function(){
					         $('#table').datagrid('fixDetailRowHeight',index);
					       },0);
					   }
					 });
					 $('#table').datagrid('fixDetailRowHeight',index);
				},
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
	
		function showGD(gd_id,gd_content_id){
			openDialogResize('<%=contextPath%>/springViews/gd/showGd.jsp?gd_id='+gd_id+'&gd_content_id='+gd_content_id,1000, 800);
		}
		
		function  viewData(id,xm_flow_status){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditXm.jsp?xm_id="+id+"&callback=rtCallBack&isShow=1&xm_flow_status="+xm_flow_status,1000, 800);
	
		}
		
		function doSearch() {
			var searchValue = $('#searchValue').val();
			var xm_progress_status = $('#xm_progress_status').combobox('getValue');
			$('#table').datagrid('load', {
				searchValue : searchValue,
				xm_progress_status:xm_progress_status
			});
		}
		
	</script>
	<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
		</div>
		<div align="right">
			项目进度：<input id="xm_progress_status" name="xm_progress_status" />&nbsp;&nbsp; 
			项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="建设单位编号/项目编号/名称" placeholder="建设单位编号/项目编号/名称 "  />&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
</body>
</html>